import { h, ref } from 'vue';
import { cloneDeep } from 'lodash-es';
import { FormSchema } from '@/components/Form';
import { defRangeShortcuts } from '@/utils/dateUtil';

export class State {
  public id = 0; // id
  public storeId = 0; // 商家 id
  public memberId = 0; // 申请人 id
  public amount = null; // 提现金额
  public to = ''; // 转到银行卡号
  public tradeNo = ''; // 流水号
  public createdAt = ''; // 申请时间

  constructor(state?: Partial<State>) {
    if (state) {
      Object.assign(this, state);
    }
  }
}

export function newState(state: State | Record<string, any> | null): State {
  if (state !== null) {
    if (state instanceof State) {
      return cloneDeep(state);
    }
    return new State(state);
  }
  return new State();
}

// 表单验证规则
export const rules = {
  storeId: {
    required: true,
    trigger: ['blur', 'input'],
    type: 'number',
    message: '请输入商家 id',
  },
  memberId: {
    required: true,
    trigger: ['blur', 'input'],
    type: 'number',
    message: '请输入申请人 id',
  },
};

// 表格搜索表单
export const schemas = ref<FormSchema[]>([
  {
    field: 'id',
    component: 'NInputNumber',
    label: 'id',
    componentProps: {
      placeholder: '请输入id',
      onUpdateValue: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'createdAt',
    component: 'NDatePicker',
    label: '申请时间',
    componentProps: {
      type: 'datetimerange',
      clearable: true,
      shortcuts: defRangeShortcuts(),
      onUpdateValue: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'storeName',
    component: 'NInput',
    label: '门店名称',
    componentProps: {
      placeholder: '请输入门店名称',
      onUpdateValue: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'storePhone',
    component: 'NInput',
    label: '门店电话',
    componentProps: {
      placeholder: '请输入门店电话',
      onUpdateValue: (e: any) => {
        console.log(e);
      },
    },
  },
  {
    field: 'adminMemberNickname',
    component: 'NInput',
    label: '微信昵称',
    componentProps: {
      placeholder: '请输入微信昵称',
      onUpdateValue: (e: any) => {
        console.log(e);
      },
    },
  },
]);

// 表格列
export const columns = [
  {
    title: 'id',
    key: 'id',
    align: 'left',
    width: -1,
  },
  {
    title: '提现金额',
    key: 'amount',
    align: 'left',
    width: -1,
  },
  {
    title: '转到银行卡号',
    key: 'to',
    align: 'left',
    width: -1,
  },
  {
    title: '流水号',
    key: 'tradeNo',
    align: 'left',
    width: -1,
  },
  {
    title: '申请时间',
    key: 'createdAt',
    align: 'left',
    width: -1,
  },
  {
    title: '门店名称',
    key: 'storeName',
    align: 'left',
    width: -1,
  },
  {
    title: '门店电话',
    key: 'storePhone',
    align: 'left',
    width: -1,
  },
  {
    title: '微信昵称',
    key: 'adminMemberNickname',
    align: 'left',
    width: -1,
  },
];